package com.mdd.usercenter.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
@ConfigurationProperties(value = "spring.redis")
@Data
public class RedissonConfig {
    private String port;

    private String host;

    private String password;

    //注册RedissonClient对象
    @Bean(destroyMethod="shutdown")
    RedissonClient redisson() throws IOException {
        Config config = new Config();
        config.useSingleServer().setAddress(String.format("redis://%s:%s",host,port)).setPassword(password).setDatabase(3);
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
